import bigDecimal from 'js-big-decimal';
import { trim } from 'lodash';

import { numberFormat } from '@/utils/formatterUtil';

const util = {
    /*
    格式化数值 num，
    isPercent：是否百分比
    decimalPlaces：小数位数
    */
    getNumberFormat(num = '', isPercent = false, decimalPlaces = 2) {
        if (trim(num)) {
            if (isPercent) {
                return numberFormat(bigDecimal.multiply(num, 100), decimalPlaces);
            }
            return numberFormat(num, decimalPlaces);
        }
        return '';
    }
};

export default util;
